﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.IO;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Text;
using Microsoft.WindowsAzure;
//using Microsoft.WindowsAzure.ServiceRuntime;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure.StorageClient.Protocol;
using System.Collections.Specialized;
using HospitalSystem.Core;
using System.Drawing;

namespace HospitalSystem
{
    public partial class reg : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        
        
        
        {

            

            string CIDstring = Request.QueryString["CID"];
          

            //ถ้ามีคิวรี่สติง ให้คิวรี่โชว์ตามคิวรี่
            if (CIDstring != null)
            {
                //reg.aspx?CID=1669800114444

                Session["CID"] = CIDstring;
                show_Images();
                show_Images2();
                show_Images3();
              
                RegShowPanel.Visible = true;
                CensusRegShowPanel.Visible = true;
                LiveRegShowPanel.Visible = true;
                loaddatareg();
                MainRegPanel.Visible = false;
                  CensusRegPanel.Visible=false;
                  LiveRegPanel.Visible=false;
                  Session["LastName"] = RLName.Text;
                  Session["FirstName"] = RFName.Text;

                  loaddatadropdownProvince();
                  loaddatadropdownProvince2();
                  loaddatadropdownTitles();
                  loaddataBloodTypeRBL();
                  loaddataForeignD();
                  loaddataGenderR();

                  joinTitles();
                  CMPlanNo();

            }

            else
            //ถ้า ไม่มีคิวรี่สติง( เข้าแค่ ChildDetails.aspx   ธรรมดา จะถือเอา sesson CID มาคิวรี่โชว์)  ทำเพื่อสำหรับหน้ากลับข้อมูลส่วนตัวจะได้กลับไปที่  ChildDetails.aspx ได้
            {
              //  reg.aspx

                if (!IsPostBack)
                {
                  
                    RegShowPanel.Visible = false;
                    CensusRegShowPanel.Visible = false;
                    LiveRegShowPanel.Visible = false;

                    MainRegPanel.Visible = true;
                    CensusRegPanel.Visible = true;
                    LiveRegPanel.Visible = true;
                    Panel1.Visible = false;
                    loaddatadropdownchildType();
                    checkinfo();
                    loaddatadropdownProvince();
                    loaddatadropdownProvince2();
                    loaddatadropdownTitles();
                    loaddataBloodTypeRBL();
                    loaddataForeignD();
                    loaddataGenderR();


                    GenderR.SelectedValue = "M";
                    CensusMoveOutReason.SelectedValue = "0";
                    LiveMoveOutReason.SelectedValue = "0";
             
                    checkinfo();
                }

            }
            
            
            
            
            
            
            
            
            
            
            
          



            //checkinfo();


        }
        //รูปด้านข้าง

        public void show_Images()
        {
            string sj = "";



            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT Child_Pic FROM [Person] where cid=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                sj = reader2["Child_Pic"].ToString();
            }
            else
            {
                sj = "~/pic/profile/nopic.jpg";
            }
            conn.Close();
            reader2.Close();


            //Image1.ImageUrl = (sj);
        }






        //รูปด้านล่าง

        public void show_Images2()
        {
            string sj = "";



            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT Child_Pic FROM [Person] where cid=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                sj = reader2["Child_Pic"].ToString();
            }
            else
            {
                sj = "~/pic/profile/nopic.jpg";
            }
            conn.Close();
            reader2.Close();


            Image2.ImageUrl = (sj);
        }






        public void show_Images3()
        {
            string sj = "";



            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT Child_PicCID FROM [Person] where cid=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                sj = reader2["Child_PicCID"].ToString();
            }
            else
            {
                sj = "~/pic/profile/nopic.jpg";
            }
            conn.Close();
            reader2.Close();


            Image3.ImageUrl = (sj);
        }


      

     



        protected void checkinfo()
        {
            //string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            //SqlConnection conn = new SqlConnection(constr);

            //SqlCommand CmdSql2 = new SqlCommand("SELECT CID FROM [Person] where CID=@CID", conn);
            //conn.Open();
            //CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            //SqlDataReader reader2 = CmdSql2.ExecuteReader();


            if (Session["CID"] == null)
            {

                edit_info.Visible = false;
                reg_button.Visible = true;
                Panel1.Visible = false;
            }

            else

            {

            



                loaddataregtb();
                edit_info.Visible = true;
                reg_button.Visible = false;
                CID.ReadOnly = true;
                show_Images();
                show_Images2();
                show_Images3();
              
             
            }

        }




        protected void Wizard1_PreRender(object sender, EventArgs e)
        {
            //Repeater SideBarList = Wizard1.FindControl("HeaderContainer").FindControl("SideBarList") as Repeater;
            //SideBarList.DataSource = Wizard1.WizardSteps;
            //SideBarList.DataBind();
        }

        //protected string GetClassForWizardStep(object wizardStep)
        //{
        //    //WizardStep step = wizardStep as WizardStep;

        //    //if (step == null)
        //    //{
        //    //    return "";
        //    //}
        //    //int stepIndex = Wizard1.WizardSteps.IndexOf(step);

        //    //if (stepIndex < Wizard1.ActiveStepIndex)
        //    //{
        //    //    return "prevStep";
        //    //}
        //    //else if (stepIndex > Wizard1.ActiveStepIndex)
        //    //{
        //    //    return "nextStep";
        //    //}
        //    //else
        //    //{
        //    //    return "currentStep";
        //    //}
        //}

        protected void AddressHomeCheckbox_CheckedChanged(object sender, EventArgs e)
        {
        }


        //Wizard1_ActiveStepChanged
        protected void Wizard1_ActiveStepChanged(object sender, EventArgs e)
        {
            //int step = Wizard1.ActiveStepIndex;
            //if (step == 1)
            //{
            //    //Insert Student Profile Data

            //}
            //else if (step == 2)
            //{

            //}
            //else if (step == 3)
            //{

            //}
            //else
            //{

            //}
        }

        //=================================================================================
        //Dropdown Bind Function
        private void BindIntroDropdownList()
        {
          
        }

        //Bind Relation DropdownList

        private void BindRelationDropdownList()
        {
        
        }

        protected void BDIB_Click(object sender, ImageClickEventArgs e)
        {
            BDCal.Visible = true;
        }

        protected void CMIDIB_Click(object sender, ImageClickEventArgs e)
        {
            CMIDCal.Visible = true;
        }

        protected void CMODIB_Click(object sender, ImageClickEventArgs e)
        {
            CMODCal.Visible = true;
        }

        protected void LMIDIB_Click(object sender, ImageClickEventArgs e)
        {
            LMIDCal.Visible = true;
        }

        protected void LMODIB_Click(object sender, ImageClickEventArgs e)
        {
            LMODCal.Visible = true;
        }

        protected void LMIDCal_SelectionChanged(object sender, EventArgs e)
        {
            LMIDTB.Text = LMIDCal.SelectedDate.ToShortDateString();
            LMIDCal.Visible = false;
        }

        protected void BDCal_SelectionChanged(object sender, EventArgs e)
        {
          birthday.Text = BDCal.SelectedDate.ToShortDateString();
            BDCal.Visible = false;
        }

        protected void CMIDCal_SelectionChanged(object sender, EventArgs e)
        {
            CMIDTB.Text = CMIDCal.SelectedDate.ToShortDateString();
          CMIDCal.Visible = false;
        }

        protected void CMODCal_SelectionChanged(object sender, EventArgs e)
        {
            CMODTB.Text = CMODCal.SelectedDate.ToShortDateString();
            CMODCal.Visible = false;
        }

        protected void LMODCal_SelectionChanged(object sender, EventArgs e)
        {
            LMODTB.Text = LMODCal.SelectedDate.ToShortDateString();
           LMODCal.Visible = false;
        }

        protected void CID_TextChanged(object sender, EventArgs e)
        {
            if (CID.Text.Length == 13)
            {
                checknumber();



            }
            else
            {
                CIDST.Visible = true;
                CIDST.Text = "กรุณาใส่เลขบัตรประจำตัวประชาชนให้ครบ13หลัก";
                CIDST.ForeColor = Color.Red;
            }


        }




        public bool ValidateNumber(string input)
        {
            foreach (char c in input)
            {
                if (!Char.IsNumber(c))
                {
                    return false;
                }

            }

            return true;
        }


        protected void checknumber()
        {
            if (ValidateNumber(CID.Text))
            {

                checkcid();

            }


            else
            {
                reg_button.Visible = false;
                CIDST.Text = "กรุณาใส่เฉพาะตัวเลข";
                CIDST.ForeColor = Color.Red;

            }

        }





        protected void checkcid()
        {

            string IDChecking = CID.Text;
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn2 = new SqlConnection(constr);
            SqlCommand cmd22 = new SqlCommand("SELECT CID FROM [Person] where CID=@CID", conn2);


            conn2.Open();
            cmd22.Parameters.AddWithValue("@CID", CID.Text);

            SqlDataReader reader32 = cmd22.ExecuteReader();


            //มี
            if (reader32.Read())
            {
                reg_button.Visible = false;
                CIDST.Visible = true;
                CIDST.Text = "เลขประจำตัวประชาชนนี้มีการลงทะเบียนแล้ว";
                CIDST.ForeColor = Color.Red;

            }
            else
            //ไม่มี
            {

                CIDST.Visible = true;


                if (IDChecking[0].Equals('1') ||
                        IDChecking[0].Equals('2') ||
                        IDChecking[0].Equals('3') ||
                        IDChecking[0].Equals('4') ||
                        IDChecking[0].Equals('5') ||
                        IDChecking[0].Equals('6') ||
                        IDChecking[0].Equals('7') ||
                        IDChecking[0].Equals('8'))
                {
                    int CalculateFinalValuefrom12 = 11 - (((int.Parse(IDChecking[0].ToString()) * 13) +
                        (int.Parse(IDChecking[1].ToString()) * 12) +
                        (int.Parse(IDChecking[2].ToString()) * 11) +
                        (int.Parse(IDChecking[3].ToString()) * 10) +
                        (int.Parse(IDChecking[4].ToString()) * 9) +
                        (int.Parse(IDChecking[5].ToString()) * 8) +
                        (int.Parse(IDChecking[6].ToString()) * 7) +
                        (int.Parse(IDChecking[7].ToString()) * 6) +
                        (int.Parse(IDChecking[8].ToString()) * 5) +
                        (int.Parse(IDChecking[9].ToString()) * 4) +
                        (int.Parse(IDChecking[10].ToString()) * 3) +
                        (int.Parse(IDChecking[11].ToString()) * 2)) % 11);
                    if (CalculateFinalValuefrom12 == 10)
                    {
                        CalculateFinalValuefrom12 = 0;
                    }
                    if (CalculateFinalValuefrom12 == 11)
                    {
                        CalculateFinalValuefrom12 = 1;
                    }

                    if (CalculateFinalValuefrom12 == int.Parse(IDChecking[12].ToString()))
                    {
                        //เลขบัตรประชาชนนี้สามารถใช้ได้
                        reg_button.Visible = true;

                        CIDST.Text = "เลขบัตรประชาชนนี้สามารถใช้ได้";
                        CIDST.ForeColor = Color.Green;
                    }
                    else
                    {
                        //เลขบัตรประชาชนนี้ไม่สามารถใช้ได้
                        reg_button.Visible = false;
                        CIDST.Text = "เลขบัตรประชาชนนี้ไม่สามารถใช้ได้";
                        CIDST.ForeColor = Color.Red;
                    }







                }


                else
                {
                    //เลขบัตรประชาชนนี้ไม่สามารถใช้ได้
                    reg_button.Visible = false;
                    CIDST.Text = "เลขบัตรประชาชนนี้ไม่สามารถใช้ได้";
                    CIDST.ForeColor = Color.Red;
                }


                conn2.Close();
                reader32.Close();
            }
        }












        protected void EditReg_Button_Click(object sender, EventArgs e)
        {
            
            Response.Redirect("reg.aspx");
        }

        protected void reg_button_Click(object sender, EventArgs e)
        {
            if (CID.Text.Length == 13)
            {
                checknumber2();



            }
            else
            {
                CIDST.Visible = true;
                CIDST.Text = "กรุณาใส่เลขบัตรประจำตัวประชาชนให้ครบ13หลัก";
                CIDST.ForeColor = Color.Red;
            }


        }



        protected void checknumber2()
        {
            if (ValidateNumber(CID.Text))
            {

                checkcid2();

            }


            else
            {
                reg_button.Visible = false;
                CIDST.Text = "กรุณาใส่เฉพาะตัวเลข";
                CIDST.ForeColor = Color.Red;

            }

        }






        protected void checkcid2()
        {

            string IDChecking = CID.Text;
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn2 = new SqlConnection(constr);
            SqlCommand cmd22 = new SqlCommand("SELECT CID FROM [Person] where CID=@CID", conn2);


            conn2.Open();
            cmd22.Parameters.AddWithValue("@CID", CID.Text);

            SqlDataReader reader32 = cmd22.ExecuteReader();


            //มี
            if (reader32.Read())
            {
                reg_button.Visible = false;
                CIDST.Visible = true;
                CIDST.Text = "เลขประจำตัวประชาชนนี้มีการลงทะเบียนแล้ว";
                CIDST.ForeColor = Color.Red;


            }
            else
            //ไม่มี
            {

                CIDST.Visible = true;


                if (IDChecking[0].Equals('1') ||
                        IDChecking[0].Equals('2') ||
                        IDChecking[0].Equals('3') ||
                        IDChecking[0].Equals('4') ||
                        IDChecking[0].Equals('5') ||
                        IDChecking[0].Equals('6') ||
                        IDChecking[0].Equals('7') ||
                        IDChecking[0].Equals('8'))
                {
                    int CalculateFinalValuefrom12 = 11 - (((int.Parse(IDChecking[0].ToString()) * 13) +
                        (int.Parse(IDChecking[1].ToString()) * 12) +
                        (int.Parse(IDChecking[2].ToString()) * 11) +
                        (int.Parse(IDChecking[3].ToString()) * 10) +
                        (int.Parse(IDChecking[4].ToString()) * 9) +
                        (int.Parse(IDChecking[5].ToString()) * 8) +
                        (int.Parse(IDChecking[6].ToString()) * 7) +
                        (int.Parse(IDChecking[7].ToString()) * 6) +
                        (int.Parse(IDChecking[8].ToString()) * 5) +
                        (int.Parse(IDChecking[9].ToString()) * 4) +
                        (int.Parse(IDChecking[10].ToString()) * 3) +
                        (int.Parse(IDChecking[11].ToString()) * 2)) % 11);
                    if (CalculateFinalValuefrom12 == 10)
                    {
                        CalculateFinalValuefrom12 = 0;
                    }
                    if (CalculateFinalValuefrom12 == 11)
                    {
                        CalculateFinalValuefrom12 = 1;
                    }

                    if (CalculateFinalValuefrom12 == int.Parse(IDChecking[12].ToString()))
                    {
                        //เลขบัตรประชาชนนี้สามารถใช้ได้
                        reg_button.Visible = true;

                        CIDST.Text = "เลขบัตรประชาชนนี้สามารถใช้ได้";
                        CIDST.ForeColor = Color.Green;

                        insert();
                        sessionsend();

                        String a;

                        //  ('reg.aspx?CID=('1669800114444')')

                        //(reg.aspx?CID=(1669800114444)')
                        a = "reg.aspx?CID=" + Session["CID"] + "";
                        Response.Redirect("" + a + "");


                    }
                    else
                    {
                        //เลขบัตรประชาชนนี้ไม่สามารถใช้ได้
                        reg_button.Visible = false;
                        CIDST.Text = "เลขบัตรประชาชนนี้ไม่สามารถใช้ได้";
                        CIDST.ForeColor = Color.Red;
                    }







                }


                else
                {
                    //เลขบัตรประชาชนนี้ไม่สามารถใช้ได้
                    reg_button.Visible = false;
                    CIDST.Text = "เลขบัตรประชาชนนี้ไม่สามารถใช้ได้";
                    CIDST.ForeColor = Color.Red;
                }


                conn2.Close();
                reader32.Close();
            }
        }













        protected void sessionsend()
        {
            Session["LastName"] = LastName.Text;
            Session["FirstName"] = FirstName.Text;
            Session["CID"] = CID.Text;
            String CIDLabel = (string)Session["CID"];
            CIDlabel.Text = CIDLabel;

        }
        protected void insert()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn2 = new SqlConnection(constr);
            SqlCommand CmdSql2 = new SqlCommand("INSERT INTO [Person] (CID,FirstName,LastName,DisabilityType) VALUES (@CID,@FirstName,@LastName,@DisabilityType)", conn2);
            conn2.Open();
            CmdSql2.Parameters.AddWithValue("@CID", CID.Text);
            CmdSql2.Parameters.AddWithValue("@LastName", LastName.Text);
            CmdSql2.Parameters.AddWithValue("@FirstName", FirstName.Text);
            CmdSql2.Parameters.AddWithValue("@DisabilityType", DisabilityType.SelectedValue);
            CmdSql2.ExecuteNonQuery();
            conn2.Close();


            sessionsend();


            SqlCommand CmdSqledu = new SqlCommand("INSERT INTO [EducationChild] (CID) VALUES (@CID)", conn2);
            conn2.Open();
            CmdSqledu.Parameters.AddWithValue("@CID", CID.Text);

            CmdSqledu.ExecuteNonQuery();
            conn2.Close();

            SqlCommand rightsinfo = new SqlCommand("INSERT INTO [ExistingWelfare] (CID) VALUES (@CID)", conn2);
            conn2.Open();
            rightsinfo.Parameters.AddWithValue("@CID", CID.Text);

            rightsinfo.ExecuteNonQuery();
            conn2.Close();




            //SqlCommand CmdSqledu = new SqlCommand("INSERT INTO [educationinfo] (CID) VALUES (@CID)", conn2);
            //conn2.Open();
            //CmdSqledu.Parameters.AddWithValue("@CID", CID.Text);

            //CmdSqledu.ExecuteNonQuery();
            //conn2.Close();

            //SqlCommand rightsinfo = new SqlCommand("INSERT INTO [rightsinfo] (CID) VALUES (@CID)", conn2);
            //conn2.Open();
            //rightsinfo.Parameters.AddWithValue("@CID", CID.Text);

            //rightsinfo.ExecuteNonQuery();
            //conn2.Close();



            //Session["LastName"] = LastName;
            //Session["FirstName"] = FirstName;  
            //Session["CID"] = CID;
            SqlCommand CmdSql = new SqlCommand("UPDATE [Person] SET Host=@Host,Title=@Title,Gender=@Gender,BloodType=@BloodType,Nation=@Nation,Race=@Race,Religion=@Religion,Foreigner=@Foreigner,LiveHomeStatus=@LiveHomeStatus,LiveHouseNumber=@LiveHouseNumber,LiveMooNumber=@LiveMooNumber,LiveVillageName=@LiveVillageName,LiveAlley=@LiveAlley,LiveStreetName=@LiveStreetName,LiveTumbon=@LiveTumbon,LiveCity=@LiveCity,LiveProvince=@LiveProvince,LivePostCode=@LivePostCode,LiveMoveOutReason=@LiveMoveOutReason,CensusHouseNumber=@CensusHouseNumber,CensusMooNumber=@CensusMooNumber,CensusVillageName=@CensusVillageName,CensusAlley=@CensusAlley,CensusStreetName=@CensusStreetName,CensusTumbon=@CensusTumbon,CensusCity=@CensusCity,CensusProvince=@CensusProvince,CensusPostCode=@CensusPostCode,CensusMoveOutReason=@CensusMoveOutReason,HomePhone=@HomePhone,Mobile=@Mobile,RecordedStaffID=@RecordedStaffID,DateTimeUpdate=@DateTimeUpdate WHERE CID=@CID", conn2);
            conn2.Open();
            CmdSql.Parameters.AddWithValue("@Host", Session["HostID"]);
            CmdSql.Parameters.AddWithValue("@Title", TitlesD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@Gender", GenderR.SelectedValue);
            CmdSql.Parameters.AddWithValue("@BloodType", BloodTypeRBL.SelectedValue);
          
            CmdSql.Parameters.AddWithValue("@CID", Session["CID"]);
            CmdSql.Parameters.AddWithValue("@Nation", NationTB.Text);
            CmdSql.Parameters.AddWithValue("@Race", RaceTB.Text);
            CmdSql.Parameters.AddWithValue("@Religion", ReligionTB.Text);
            CmdSql.Parameters.AddWithValue("@Foreigner", ForeignD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LiveHomeStatus", LHomeTB.Text);
            //CmdSql.Parameters.AddWithValue("@EducationStatus", EducationStatus.SelectedValue);
            //บ้านเลขที่
            CmdSql.Parameters.AddWithValue("@LiveHouseNumber", LHomeTB.Text);
            //ชื่อถนน
            CmdSql.Parameters.AddWithValue("@LiveStreetName", LStreetTB.Text);
            CmdSql.Parameters.AddWithValue("@LiveTumbon", LTambonD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LiveCity", LCityD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LiveProvince", LProvinceD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LivePostCode", LPostcodeTB.Text);

            CmdSql.Parameters.AddWithValue("@CensusHouseNumber", CHomeTB.Text);
            CmdSql.Parameters.AddWithValue("@CensusStreetName", CStreetTB.Text);
            CmdSql.Parameters.AddWithValue("@Censustumbon", CTambonD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusCity", CCityD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusProvince", CProvinceD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusPostCode", CPostcodeTB.Text);
            CmdSql.Parameters.AddWithValue("@HomePhone", CTelTB.Text);
            CmdSql.Parameters.AddWithValue("@Mobile", CCellphoneTB.Text);
            CmdSql.Parameters.AddWithValue("@RecordedStaffID", Session["Staff_id"]);
            CmdSql.Parameters.AddWithValue("@DateTimeUpdate", DateTime.Now);


            CmdSql.Parameters.AddWithValue("@LiveMoveOutReason", LiveMoveOutReason.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusMoveOutReason", CensusMoveOutReason.SelectedValue);
      


            CmdSql.Parameters.AddWithValue("@CensusMooNumber", CGroupTB.Text);
            CmdSql.Parameters.AddWithValue("@CensusVillageName", CHomeNTB.Text);
            CmdSql.Parameters.AddWithValue("@CensusAlley", CSoyTB.Text);

            CmdSql.Parameters.AddWithValue("@LiveMooNumber", LGroupTB.Text);
            CmdSql.Parameters.AddWithValue("@LiveVillageName", LHomeNTB.Text);
            CmdSql.Parameters.AddWithValue("@LiveAlley", LSoyTB.Text);

            CmdSql.ExecuteNonQuery();
            conn2.Close();

            dbotextbox();
            //MessageBox("ลงทะเบียนเรียบร้อยครับ");
        }











        //ดึงข้อมูลมาโชว์หน้า reg.aspx




        protected void loaddatareg()
        {








            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT CID,Title,FirstName,LastName,DOB,Gender,BloodType,Nation,Race,Religion,DisabilityType,Foreigner,LiveHomeStatus,LiveHouseNumber,LiveMooNumber,LiveVillageName,LiveAlley,LiveStreetName,LiveTumbon,LiveCity,LiveProvince,LivePostCode,LiveMoveInDate,LiveMoveOutDate,LiveMoveOutReason,CensusHouseNumber,CensusMooNumber,CensusVillageName,CensusAlley,CensusStreetName,CensusTumbon,CensusCity,CensusProvince,CensusPostCode,CensusMoveInDate,CensusMoveOutDate,CensusMoveOutReason,HomePhone,Mobile,RecordedStaffID,DateTimeUpdate FROM [Person] where CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            //CmdSql.Parameters.AddWithValue("@Gender", RadioButtonList1.SelectedValue);
            // CmdSql.Parameters.AddWithValue("@BloodType", RadioButtonList2.SelectedValue);





            // CensusCity,CensusProvince,CensusPostcode,HomePhone,Mobile,RecordedStaffID
            if (reader2.Read())
            {
                //Gender.SelectedValue = reader2["Gender"].ToString();
                //BloodTypeLB.Text = reader2["BloodType"].ToString();
                joinBloodType();
                RFName.Text = reader2["FirstName"].ToString();
                RLName.Text = reader2["LastName"].ToString();


                RCIDLBL.Text = reader2["CID"].ToString();
                DBOLB.Text = reader2["DOB"].ToString();
                NationLB.Text = reader2["Nation"].ToString();
                RaceLB.Text = reader2["Race"].ToString();
                ReligionLB.Text = reader2["Religion"].ToString();

                //  ForeignerLB.Text = reader2["Foreigner"].ToString();
                joinForeigner();

                LHomeLB.Text = reader2["LiveHouseNumber"].ToString();
                LStreetLB.Text = reader2["LiveStreetName"].ToString();

                //LCityLB.Text = reader2["LiveCity"].ToString();
                //LProvinceLB.Text = reader2["LiveProvince"].ToString();
                LPostcodeLB.Text = reader2["LivePostCode"].ToString();
                CHomeLB.Text = reader2["CensusHouseNumber"].ToString();
                CStreetLB.Text = reader2["CensusStreetName"].ToString();

                joinLiveTumbon();
                joinCensusTumbon();
                //CCityLB.Text = reader2["CensusCity"].ToString();
                joinLiveProvince();
                joinCensusProvince();
                joinCensusCity();
                joinLiveCity();
                //CProvinceLB.Text = reader2["CensusProvince"].ToString();
                CPostcodeLB.Text = reader2["CensusPostCode"].ToString();
                CTelLB.Text = reader2["HomePhone"].ToString();
                CCellphoneLB.Text = reader2["Mobile"].ToString();
                //RecordedStaffID.Text = reader2["RecordedStaffID"].ToString();

                ////LiveMoveInDate,LiveMoveOutDate,CensusMoveInDate,CensusMoveOutDate  LiveMoveOutReason,CensusMoveOutReason
                LMORLB.Text = reader2["LiveMoveOutReason"].ToString();
                CMORLB.Text = reader2["CensusMoveOutReason"].ToString();
                LMIDLB.Text = reader2["LiveMoveInDate"].ToString();
                LMODLB.Text = reader2["LiveMoveOutDate"].ToString();
                CMIDLB.Text = reader2["CensusMoveInDate"].ToString();
                CMOBLB.Text = reader2["CensusMoveOutDate"].ToString();



                CGroupLB.Text = reader2["CensusMooNumber"].ToString();
                CVillageLB.Text = reader2["CensusVillageName"].ToString();
                CSoyLB.Text = reader2["CensusAlley"].ToString();
                LGroupLB.Text = reader2["LiveMooNumber"].ToString();
                LVillageLB.Text = reader2["LiveVillageName"].ToString();
                LSoyLB.Text = reader2["LiveAlley"].ToString();



                //EducationStatus.Text = reader2["EducationStatus"].ToString();
                //LiveHomeStatus.Text = reader2["LiveHomeStatus"].ToString();
                //DropDownList1.Text = reader2["Title"].ToString();





                //CmdSql.Parameters.AddWithValue("@CensusHouseMoo", CGroupTB.Text);
                //CmdSql.Parameters.AddWithValue("@CensusHouseName", CHomeNTB.Text);
                //CmdSql.Parameters.AddWithValue("@CensusHousesoy", CSoyTB.Text);
                //CmdSql.Parameters.AddWithValue("@LiveHouseMoo", LGroupTB.Text);
                //CmdSql.Parameters.AddWithValue("@LiveHouseName", LHomeNTB.Text);





                //   RadioButtonList1.Text = reader2["FMstatust"].ToString();
                //     RadioButton1.Text = reader2["FMstatust"].ToString();
            }
            else
            {
                //MessageBox("ไม่พบเลขบัตรครับ");
            }
            conn.Close();
            reader2.Close();








        }








        protected void loaddataregtb()
        {

            //loaddatadropdownCityall();
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT CID,Title,FirstName,LastName,DOB,Gender,BloodType,Nation,Race,Religion,DisabilityType,Foreigner,LiveHomeStatus,LiveHouseNumber,LiveMooNumber,LiveVillageName,LiveAlley,LiveStreetName,LiveTumbon,LiveCity,LiveProvince,LivePostCode,LiveMoveInDate,LiveMoveOutDate,LiveMoveOutReason,CensusHouseNumber,CensusMooNumber,CensusVillageName,CensusAlley,CensusStreetName,CensusTumbon,CensusCity,CensusProvince,CensusPostCode,CensusMoveInDate,CensusMoveOutDate,CensusMoveOutReason,HomePhone,Mobile,RecordedStaffID,DateTimeUpdate FROM [Person] where CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            //CmdSql.Parameters.AddWithValue("@Gender", RadioButtonList1.SelectedValue);
            // CmdSql.Parameters.AddWithValue("@BloodType", RadioButtonList2.SelectedValue);





            // CensusCity,CensusProvince,CensusPostcode,HomePhone,Mobile,RecordedStaffID
            if (reader2.Read())
            {
                CID.Text = reader2["CID"].ToString();
                GenderR.SelectedValue = reader2["Gender"].ToString();
                BloodTypeLB.Text = reader2["BloodType"].ToString();
                FirstName.Text = reader2["FirstName"].ToString();
                LastName.Text = reader2["LastName"].ToString();
                RCIDLBL.Text = reader2["CID"].ToString();
                birthday.Text = reader2["DOB"].ToString();
                NationTB.Text = reader2["Nation"].ToString();
                RaceTB.Text = reader2["Race"].ToString();
                ReligionTB.Text = reader2["Religion"].ToString();
                ForeignD.SelectedValue = reader2["Foreigner"].ToString();
                LHomeTB.Text = reader2["LiveHouseNumber"].ToString();
                LStreetTB.Text = reader2["LiveStreetName"].ToString();
                DisabilityType.SelectedValue = reader2["DisabilityType"].ToString();

                LProvinceD.SelectedValue = reader2["LiveProvince"].ToString();
                loaddatadropdownLCity();
                LCityD.SelectedValue = reader2["LiveCity"].ToString();
                loaddatadropdownLTambon();
                LTambonD.SelectedValue = reader2["LiveTumbon"].ToString();



                LPostcodeTB.Text = reader2["LivePostCode"].ToString();
                CHomeTB.Text = reader2["CensusHouseNumber"].ToString();
                CStreetTB.Text = reader2["CensusStreetName"].ToString();



                //ต้องสร้าง dropdownlist ก่อนเรียกโหลดค่า
                CProvinceD.SelectedValue = reader2["CensusProvince"].ToString();
                loaddatadropdownCCity();
                CCityD.SelectedValue = reader2["CensusCity"].ToString();
                loaddatadropdownCTambon();
                CTambonD.SelectedValue = reader2["Censustumbon"].ToString();



                CPostcodeTB.Text = reader2["CensusPostcode"].ToString();
                CTelTB.Text = reader2["HomePhone"].ToString();
                CCellphoneTB.Text = reader2["Mobile"].ToString();
                //RecordedStaffID.Text = reader2["RecordedStaffID"].ToString();

                ////LiveMoveInDate,LiveMoveOutDate,CensusMoveInDate,CensusMoveOutDate  LiveMoveOutReason,CensusMoveOutReason
                LiveMoveOutReason.SelectedValue = reader2["LiveMoveOutReason"].ToString();
                CensusMoveOutReason.SelectedValue = reader2["CensusMoveOutReason"].ToString();

                LMIDTB.Text = reader2["LiveMoveInDate"].ToString();
                LMODTB.Text = reader2["LiveMoveOutDate"].ToString();
                CMIDTB.Text = reader2["CensusMoveInDate"].ToString();
                CMODTB.Text = reader2["CensusMoveOutDate"].ToString();



                CGroupTB.Text = reader2["CensusMooNumber"].ToString();
                CHomeNTB.Text = reader2["CensusVillageName"].ToString();
                CSoyTB.Text = reader2["CensusAlley"].ToString();
                LGroupTB.Text = reader2["LiveMooNumber"].ToString();
                LHomeNTB.Text = reader2["LiveVillageName"].ToString();
                LSoyTB.Text = reader2["LiveAlley"].ToString();



                //EducationStatus.Text = reader2["EducationStatus"].ToString();
                //LiveHomeStatus.Text = reader2["LiveHomeStatus"].ToString();
                //DropDownList1.Text = reader2["Title"].ToString();





                //CmdSql.Parameters.AddWithValue("@CensusHouseMoo", CGroupTB.Text);
                //CmdSql.Parameters.AddWithValue("@CensusHouseName", CHomeNTB.Text);
                //CmdSql.Parameters.AddWithValue("@CensusHousesoy", CSoyTB.Text);
                //CmdSql.Parameters.AddWithValue("@LiveHouseMoo", LGroupTB.Text);
                //CmdSql.Parameters.AddWithValue("@LiveHouseName", LHomeNTB.Text);






                //   RadioButtonList1.Text = reader2["FMstatust"].ToString();
                //     RadioButton1.Text = reader2["FMstatust"].ToString();
            }
            else
            {
                //MessageBox("ไม่พบเลขบัตรครับ");
            }
            conn.Close();
            reader2.Close();








        }

        protected void edit_info_Click(object sender, EventArgs e)
        {
            
            updatetb();

            String a;

            //  ('reg.aspx?CID=('1669800114444')')

            //(reg.aspx?CID=(1669800114444)')
            a = "reg.aspx?CID=" + Session["CID"] + "";
            Response.Redirect("" + a + "");
        }







        protected void Imagesavetodb()
        {
            String pic;
            pic = "https://sp01.blob.core.windows.net/pic/" + Session["CID"] + "";


            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;

            SqlConnection scon = new SqlConnection(constr);
            SqlCommand cmd22 = new SqlCommand("UPDATE [Person] set Child_Pic=@FilePath where CID=@Iddek", scon);
            cmd22.Parameters.AddWithValue("@Iddek", RCIDLBL.Text);

            cmd22.Parameters.AddWithValue("@FilePath", pic);

            scon.Open();
            cmd22.ExecuteNonQuery();
            scon.Close();
        }




        protected void ImageUpload_f()
        {

            if (imageFile.HasFile)
            {
                Imagesavetodb();
                status.Text = "Inserted [" + imageFile.FileName + "] - Content Type [" + imageFile.PostedFile.ContentType + "] - Length [" + imageFile.PostedFile.ContentLength + "]";

                this.SaveImage(
                  Guid.NewGuid().ToString(),
                  (string)Session["CID"],
                  (string)Session["CID"],
                  (string)Session["CID"],
                  imageFile.FileName,
                  imageFile.PostedFile.ContentType,
                  imageFile.FileBytes
                );

                //RefreshGallery();
                Imagesavetodb();
            }
            else
                status.Text = "No image file";
        }



        private void SaveImage(string id, string name, string description, string tags, string fileName, string contentType, byte[] data)
        {
            // Create a blob in container and upload image bytes to it
            var blob = this.GetContainer().GetBlobReference(name);

            blob.Properties.ContentType = contentType;

            // Create some metadata for this image
            var metadata = new NameValueCollection();
            metadata["Id"] = id;
            metadata["Filename"] = fileName;
            metadata["ImageName"] = String.IsNullOrEmpty(name) ? "unknown" : name;
            metadata["Description"] = String.IsNullOrEmpty(description) ? "unknown" : description;
            metadata["Tags"] = String.IsNullOrEmpty(tags) ? "unknown" : tags;

            // Add and commit metadata to blob
            blob.Metadata.Add(metadata);
            blob.UploadByteArray(data);


        }


        private CloudBlobContainer GetContainer()
        {
            // Get a handle on account, create a blob service client and get container proxy
            //var account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
            //var client = account.CreateCloudBlobClient();
            //return blobClient.GetContainerReference(RoleEnvironment.GetConfigurationSettingValue("ContainerName"));

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve a reference to a container. 
            CloudBlobContainer container = blobClient.GetContainerReference("pic");

            // Create the container if it doesn't already exist.
            BlobContainerPermissions permission = new BlobContainerPermissions();
            permission.PublicAccess = BlobContainerPublicAccessType.Off;
            SharedAccessPolicy policy = new SharedAccessPolicy();
            policy.Permissions = SharedAccessPermissions.None;
            permission.SharedAccessPolicies.Add("abc", policy);

            //container.SetPermissions(permission);

            container.CreateIfNotExist();
            return container;
        }














        protected void Imagesavetodb2()
        {
            String pic;
            pic = "https://sp01.blob.core.windows.net/cid/" + Session["CID"] + "";


            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;

            SqlConnection scon = new SqlConnection(constr);
            SqlCommand cmd22 = new SqlCommand("UPDATE [Person] set Child_PicCID=@FilePath where CID=@Iddek", scon);
            cmd22.Parameters.AddWithValue("@Iddek", RCIDLBL.Text);

            cmd22.Parameters.AddWithValue("@FilePath", pic);

            scon.Open();
            cmd22.ExecuteNonQuery();
            scon.Close();
        }


        protected void ImageUpload_2()
        {

            if (FileUpload3.HasFile)
            {

                status.Text = "Inserted [" + FileUpload3.FileName + "] - Content Type [" + FileUpload3.PostedFile.ContentType + "] - Length [" + FileUpload3.PostedFile.ContentLength + "]";

                this.SaveImage2(
                  Guid.NewGuid().ToString(),
                  (string)Session["CID"],
                  (string)Session["CID"],
                  (string)Session["CID"],
                  FileUpload3.FileName,
                  FileUpload3.PostedFile.ContentType,
                  FileUpload3.FileBytes
                );

                //RefreshGallery();
                Imagesavetodb2();
            }
            else
                status.Text = "No image file";
        }




        private void SaveImage2(string id, string name, string description, string tags, string fileName, string contentType, byte[] data)
        {
            // Create a blob in container and upload image bytes to it
            var blob2 = this.GetContainer2().GetBlobReference(name);

            blob2.Properties.ContentType = contentType;

            // Create some metadata for this image
            var metadata2 = new NameValueCollection();
            metadata2["Id"] = id;
            metadata2["Filename"] = fileName;
            metadata2["ImageName"] = String.IsNullOrEmpty(name) ? "  unknown" : name;
            metadata2["Description"] = String.IsNullOrEmpty(description) ? "unknown" : description;
            metadata2["Tags"] = String.IsNullOrEmpty(tags) ? "unknown" : tags;

            // Add and commit metadata to blob
            blob2.Metadata.Add(metadata2);
            blob2.UploadByteArray(data);


        }


        private CloudBlobContainer GetContainer2()
        {
            // Get a handle on account, create a blob service client and get container proxy
            //var account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
            //var client = account.CreateCloudBlobClient();
            //return blobClient.GetContainerReference(RoleEnvironment.GetConfigurationSettingValue("ContainerName"));

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve a reference to a container. 
            CloudBlobContainer container = blobClient.GetContainerReference("cid");

            // Create the container if it doesn't already exist.
            BlobContainerPermissions permission = new BlobContainerPermissions();
            permission.PublicAccess = BlobContainerPublicAccessType.Off;
            SharedAccessPolicy policy = new SharedAccessPolicy();
            policy.Permissions = SharedAccessPermissions.None;
            permission.SharedAccessPolicies.Add("abc", policy);

            //container.SetPermissions(permission);

            container.CreateIfNotExist();
            return container;
        }




        


        protected void updatetb()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn2 = new SqlConnection(constr);




            SqlCommand CmdSql = new SqlCommand("UPDATE [Person] SET Host=@Host,FirstName=@FirstName,LastName=@LastName,DisabilityType=@DisabilityType,Title=@Title,DOB=@DOB,Gender=@Gender,BloodType=@BloodType,Nation=@Nation,Race=@Race,Religion=@Religion,Foreigner=@Foreigner,LiveHomeStatus=@LiveHomeStatus,LiveHouseNumber=@LiveHouseNumber,LiveMooNumber=@LiveMooNumber,LiveVillageName=@LiveVillageName,LiveAlley=@LiveAlley,LiveStreetName=@LiveStreetName,LiveTumbon=@LiveTumbon,LiveCity=@LiveCity,LiveProvince=@LiveProvince,LivePostCode=@LivePostCode,LiveMoveInDate=@LiveMoveInDate,LiveMoveOutDate=@LiveMoveOutDate,LiveMoveOutReason=@LiveMoveOutReason,CensusHouseNumber=@CensusHouseNumber,CensusMooNumber=@CensusMooNumber,CensusVillageName=@CensusVillageName,CensusAlley=@CensusAlley,CensusStreetName=@CensusStreetName,CensusTumbon=@CensusTumbon,CensusCity=@CensusCity,CensusProvince=@CensusProvince,CensusPostCode=@CensusPostCode,CensusMoveInDate=@CensusMoveInDate,CensusMoveOutDate=@CensusMoveOutDate,CensusMoveOutReason=@CensusMoveOutReason,HomePhone=@HomePhone,Mobile=@Mobile,RecordedStaffID=@RecordedStaffID,DateTimeUpdate=@DateTimeUpdate WHERE CID=@CID", conn2);
            conn2.Open();
            CmdSql.Parameters.AddWithValue("@LastName", LastName.Text);
            CmdSql.Parameters.AddWithValue("@FirstName", FirstName.Text);
            CmdSql.Parameters.AddWithValue("@Host", Session["HostID"]);
            CmdSql.Parameters.AddWithValue("@DisabilityType", DisabilityType.SelectedValue);
            CmdSql.Parameters.AddWithValue("@Title", TitlesD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@Gender", GenderR.SelectedValue);
            CmdSql.Parameters.AddWithValue("@BloodType", BloodTypeRBL.SelectedValue);
            CmdSql.Parameters.AddWithValue("@DOB", birthday.Text);
            CmdSql.Parameters.AddWithValue("@CID", Session["CID"]);
            CmdSql.Parameters.AddWithValue("@Nation", NationTB.Text);
            CmdSql.Parameters.AddWithValue("@Race", RaceTB.Text);
            CmdSql.Parameters.AddWithValue("@Religion", ReligionTB.Text);
            CmdSql.Parameters.AddWithValue("@Foreigner", ForeignD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LiveHomeStatus", LHomeTB.Text);
            //CmdSql.Parameters.AddWithValue("@EducationStatus", EducationStatus.SelectedValue);
            //บ้านเลขที่
            CmdSql.Parameters.AddWithValue("@LiveHouseNumber", LHomeTB.Text);
            //ชื่อถนน
            CmdSql.Parameters.AddWithValue("@LiveStreetName", LStreetTB.Text);
            CmdSql.Parameters.AddWithValue("@LiveTumbon", LTambonD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LiveCity", LCityD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LiveProvince", LProvinceD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LivePostCode", LPostcodeTB.Text);

            CmdSql.Parameters.AddWithValue("@CensusHouseNumber", CHomeTB.Text);
            CmdSql.Parameters.AddWithValue("@CensusStreetName", CStreetTB.Text);
            CmdSql.Parameters.AddWithValue("@Censustumbon", CTambonD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusCity", CCityD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusProvince", CProvinceD.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusPostCode", CPostcodeTB.Text);
            CmdSql.Parameters.AddWithValue("@HomePhone", CTelTB.Text);
            CmdSql.Parameters.AddWithValue("@Mobile", CCellphoneTB.Text);
            CmdSql.Parameters.AddWithValue("@RecordedStaffID", Session["Staff_id"]);
            CmdSql.Parameters.AddWithValue("@DateTimeUpdate", DateTime.Now);

            CmdSql.Parameters.AddWithValue("@LiveMoveInDate", LMIDTB.Text);
            CmdSql.Parameters.AddWithValue("@LiveMoveOutReason", LiveMoveOutReason.SelectedValue);
            CmdSql.Parameters.AddWithValue("@CensusMoveOutReason", CensusMoveOutReason.SelectedValue);
            CmdSql.Parameters.AddWithValue("@LiveMoveOutDate", LMODTB.Text);


            CmdSql.Parameters.AddWithValue("@CensusMoveOutDate", CMODTB.Text);
            CmdSql.Parameters.AddWithValue("@CensusMoveInDate", CMIDTB.Text);

            CmdSql.Parameters.AddWithValue("@CensusMooNumber", CGroupTB.Text);
            CmdSql.Parameters.AddWithValue("@CensusVillageName", CHomeNTB.Text);
            CmdSql.Parameters.AddWithValue("@CensusAlley", CSoyTB.Text);

            CmdSql.Parameters.AddWithValue("@LiveMooNumber", LGroupTB.Text);
            CmdSql.Parameters.AddWithValue("@LiveVillageName", LHomeNTB.Text);
            CmdSql.Parameters.AddWithValue("@LiveAlley", LSoyTB.Text);

            CmdSql.ExecuteNonQuery();
            conn2.Close();

            dbotextbox();
        }

        protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
        {
            Response.Redirect("regfamily.aspx");
        }
        //     อัพรูป
     

        protected void Button_picedit_Click(object sender, EventArgs e)
        {
            Panel1.Visible = true;
        }

        protected void uploadpic_Click(object sender, EventArgs e)
        {
            ImageUpload_f();
            ImageUpload_2();
      
            String a;
            a = "reg.aspx?CID=" + Session["CID"] + "";
            Response.Redirect("" + a + "");
        }














        public void loaddatadropdownchildType()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT Name,DisabilityCode FROM DisabilityType", conn);
            conn.Open();

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dt = new DataTable();
            DisabilityType.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "ประเภทความพิการ";
            newItem.Value = "0";
            DisabilityType.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["Name"].ToString();
                newItem.Value = reader4["DisabilityCode"].ToString();
                DisabilityType.Items.Add(newItem);
            }

        }






        public void loaddatadropdownProvince()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT ProvinceID,ProvinceDescription FROM Province", conn);
            conn.Open();

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dt = new DataTable();
            CProvinceD.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "เลือกจังหวัด";
            newItem.Value = "0";
            CProvinceD.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["ProvinceDescription"].ToString();
                newItem.Value = reader4["ProvinceID"].ToString();
                CProvinceD.Items.Add(newItem);
            }

        }

        public void loaddatadropdownProvince2()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT ProvinceID,ProvinceDescription FROM Province", conn);
            conn.Open();

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dt = new DataTable();
            LProvinceD.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "เลือกจังหวัด";
            newItem.Value = "0";
            LProvinceD.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["ProvinceDescription"].ToString();
                newItem.Value = reader4["ProvinceID"].ToString();
                LProvinceD.Items.Add(newItem);
            }

        }

        public void loaddatadropdownTitles()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT TitleID,Description FROM Title", conn);
            conn.Open();

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtt = new DataTable();
            TitlesD.Items.Clear();
            ListItem newItem = new ListItem();
           

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["Description"].ToString();
                newItem.Value = reader4["TitleID"].ToString();
                TitlesD.Items.Add(newItem);
            }

        }






        public void loaddataBloodTypeRBL()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT BloodTypeID,BloodTypeDescription FROM BloodType", conn);
            conn.Open();

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtBloodTypeRBL = new DataTable();
            BloodTypeRBL.Items.Clear();
            ListItem newItem = new ListItem();


            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["BloodTypeDescription"].ToString();
                newItem.Value = reader4["BloodTypeID"].ToString();
                BloodTypeRBL.Items.Add(newItem);
            }

        }




        public void loaddataGenderR()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT GenderCode,GenderThaiDescription FROM [HL7 Gender Standard]", conn);
            conn.Open();

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtGenderR = new DataTable();
            GenderR.Items.Clear();
            ListItem newItem = new ListItem();


            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["GenderThaiDescription"].ToString();
                newItem.Value = reader4["GenderCode"].ToString();
                GenderR.Items.Add(newItem);
            }

        }


        public void loaddataForeignD()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT ForeignTypeID,ForeignTypeDescription FROM Foreigner", conn);
            conn.Open();

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtForeignD = new DataTable();
            ForeignD.Items.Clear();
            ListItem newItem = new ListItem();


            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["ForeignTypeDescription"].ToString();
                newItem.Value = reader4["ForeignTypeID"].ToString();
                ForeignD.Items.Add(newItem);
            }

        }


       



        public void loaddatadropdownCCity()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT CityID,CityDescription FROM City where ProvinceID=@ProvinceID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@ProvinceID", CProvinceD.SelectedValue);

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtCCityD = new DataTable();
            CCityD.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "เลือกอำเภอ";
            newItem.Value = "0";
            CCityD.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["CityDescription"].ToString();
                newItem.Value = reader4["CityID"].ToString();
                CCityD.Items.Add(newItem);
            }

        }


        public void loaddatadropdownLCity()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT CityID,CityDescription FROM City where ProvinceID=@ProvinceID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@ProvinceID", LProvinceD.SelectedValue);

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtLCityD = new DataTable();
            LCityD.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "เลือกอำเภอ";
            newItem.Value = "0";
            LCityD.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["CityDescription"].ToString();
                newItem.Value = reader4["CityID"].ToString();
                LCityD.Items.Add(newItem);
            }

        }





        public void loaddatadropdownCTambon()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT TumbonID,TumbonDescription FROM Tumbon where CityID=@CityID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CityID", CCityD.SelectedValue);

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtCTambon = new DataTable();
            CTambonD.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "เลือกตำบล";
            newItem.Value = "0";
            CTambonD.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["TumbonDescription"].ToString();
                newItem.Value = reader4["TumbonID"].ToString();
                CTambonD.Items.Add(newItem);
            }

        }




        public void loaddatadropdownLTambon()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT TumbonID,TumbonDescription FROM Tumbon where CityID=@CityID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CityID", LCityD.SelectedValue);

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtLTambon = new DataTable();
            LTambonD.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "เลือกตำบล";
            newItem.Value = "0";
            LTambonD.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["TumbonDescription"].ToString();
                newItem.Value = reader4["TumbonID"].ToString();
                LTambonD.Items.Add(newItem);
            }

        }










        protected void CProvinceD_SelectedIndexChanged(object sender, EventArgs e)
        {
            loaddatadropdownCCity();
        }

        protected void CCityD_SelectedIndexChanged(object sender, EventArgs e)
        {
            loaddatadropdownCTambon();
        }

        protected void LProvinceD_SelectedIndexChanged(object sender, EventArgs e)
        {
            loaddatadropdownLCity();
        }

        protected void LCityD_SelectedIndexChanged(object sender, EventArgs e)
        {
            loaddatadropdownLTambon();
        }


        public void loaddatadropdownCityall()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT CityID,CityDescription FROM City", conn);
            conn.Open();
          

            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dtCCityD = new DataTable();
            CCityD.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "เลือกอำเภอ";
            newItem.Value = "0";
            CCityD.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["CityDescription"].ToString();
                newItem.Value = reader4["CityID"].ToString();
                CCityD.Items.Add(newItem);
            }

        }

        protected void LiveCopyCheck_CheckedChanged(object sender, EventArgs e)
        {
            if (LiveCopyCheck.Checked == true)
            {

                bindtextbox();

            }

            else

            {


                String CensusHousesoys = "";
                LSoyTB.Text = CensusHousesoys;

                String CensusHouseNames = "";
                LHomeNTB.Text = CensusHouseNames;

                String CensusHouseMoos = "";
                LGroupTB.Text = CensusHouseMoos;




                String StreetAddress = "";
                LHomeTB.Text = StreetAddress;
                String StreetName = "";
                LStreetTB.Text = StreetName;

            


                loaddatadropdownLCity();


              

                String Postcode = "";
                LPostcodeTB.Text = Postcode;

                loaddatadropdownLTambon();

                loaddatadropdownProvince2();
                //String inhome = (string)Session["MIDTB"];
                //LMIDTB.Text = inhome;
                //String outhome = (string)Session["MODTB"];
                //LMODTB.Text = outhome;
            
            }
          
        }







        protected void bindtextbox()
        {



            Session["HomeTB"] = CHomeTB.Text;
            Session["GroupTB"] = CGroupTB.Text;
            Session["HomeNTB"] = CHomeNTB.Text;
            Session["SoyTB"] = CSoyTB.Text;
            Session["StreetTB"] = CStreetTB.Text;


            Session["ProvinceD"] = CProvinceD.SelectedValue;

            Session["CityD"] = CCityD.SelectedValue;
            Session["TambonD"] = CTambonD.SelectedValue;
            Session["PostcodeTB"] = CPostcodeTB.Text;
            Session["MIDTB"] = CMIDTB.Text;
            Session["MODTB"] = CMODTB.Text;

            Session["CensusMoveOutReason"] = CensusMoveOutReason.SelectedValue;


            String CensusMoveOutReasons = (string)Session["CensusMoveOutReason"];
            LiveMoveOutReason.SelectedValue = CensusMoveOutReasons;











            String CensusHousesoys = (string)Session["SoyTB"];
            LSoyTB.Text = CensusHousesoys;

            String CensusHouseNames = (string)Session["HomeNTB"];
            LHomeNTB.Text = CensusHouseNames;

            String CensusHouseMoos = (string)Session["GroupTB"];
            LGroupTB.Text = CensusHouseMoos;




            String StreetAddress = (string)Session["HomeTB"];
            LHomeTB.Text = StreetAddress;
            String StreetName = (string)Session["StreetTB"];
            LStreetTB.Text = StreetName;

            String Province = (string)Session["ProvinceD"];
            LProvinceD.SelectedValue = Province;


            loaddatadropdownLCity();


            String City = (string)Session["CityD"];
            LCityD.SelectedValue = City;

            String Postcode = (string)Session["PostcodeTB"];
            LPostcodeTB.Text = Postcode;

            loaddatadropdownLTambon();

            String tumbon = (string)Session["TambonD"];
            LTambonD.SelectedValue = tumbon;

            String inhome = (string)Session["MIDTB"];
            LMIDTB.Text = inhome;
            String outhome = (string)Session["MODTB"];
            LMODTB.Text = outhome;

        }




        protected void joinLiveProvince()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT  Province.[ProvinceDescription] as LiveProvince  FROM [Province] Province join [Person] Person on Person.LiveProvince=Province.ProvinceID  where Person.CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                LProvinceLB.Text = reader2["LiveProvince"].ToString();
            }
            else
            {
                //MessageBox("ไม่พบเลขบัตรครับ");
            }
            conn.Close();
            reader2.Close();


        }



        protected void joinCensusProvince()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT  Province.[ProvinceDescription] as CensusProvince  FROM [Province] Province join [Person] Person on Person.CensusProvince=Province.ProvinceID  where Person.CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                CProvinceLB.Text = reader2["CensusProvince"].ToString();
            }
            else
            {

            }
            conn.Close();
            reader2.Close();


        }






        protected void joinCensusCity()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT  Province.[CityDescription] as CensusCity  FROM [City] Province join [Person] Person on Person.CensusCity=Province.CityID  where Person.CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                CCityLB.Text = reader2["CensusCity"].ToString();
            }
            else
            {

            }
            conn.Close();
            reader2.Close();


        }

        protected void joinLiveCity()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT  Province.[CityDescription] as LiveCity  FROM [City] Province join [Person] Person on Person.LiveCity=Province.CityID  where Person.CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                LCityLB.Text = reader2["LiveCity"].ToString();
            }
            else
            {

            }
            conn.Close();
            reader2.Close();


        }








        protected void joinCensusTumbon()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT  Province.[TumbonDescription] as CensusTumbon  FROM [Tumbon] Province join [Person] Person on Person.CensusTumbon=Province.TumbonID  where Person.CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                CTambonLB.Text = reader2["CensusTumbon"].ToString();
            }
            else
            {

            }
            conn.Close();
            reader2.Close();


        }









        protected void joinLiveTumbon()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT  Province.[TumbonDescription] as CensusTumbon  FROM [Tumbon] Province join [Person] Person on Person.LiveTumbon=Province.TumbonID  where Person.CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                LTambonLB.Text = reader2["CensusTumbon"].ToString();
            }
            else
            {

            }
            conn.Close();
            reader2.Close();


        }








        protected void joinBloodType()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT  Province.[BloodTypeDescription] as BloodTypeDescription  FROM [BloodType] Province join [Person] Person on Person.BloodType=Province.BloodTypeID  where Person.CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                BloodTypeLB.Text = reader2["BloodTypeDescription"].ToString();
            }
            else
            {

            }
            conn.Close();
            reader2.Close();


        }


        protected void joinForeigner()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT  Province.[ForeignTypeDescription] as ForeignTypeDescription  FROM [Foreigner] Province join [Person] Person on Person.Foreigner=Province.ForeignTypeID  where Person.CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                ForeignerLB.Text = reader2["ForeignTypeDescription"].ToString();
            }
            else
            {

            }
            conn.Close();
            reader2.Close();


        }





        protected void joinTitles()
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);


            SqlCommand CmdSql2 = new SqlCommand("SELECT  Province.[Description] as ForeignTypeDescription  FROM [Title] Province join [Person] Person on Person.Title=Province.TitleID  where Person.CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();

            if (reader2.Read())
            {
                TitlesL.Text = reader2["ForeignTypeDescription"].ToString();
            }
            else
            {

            }
            conn.Close();
            reader2.Close();


        }







        protected void Button1_Click(object sender, EventArgs e)
        {

            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn2 = new SqlConnection(constr);




            SqlCommand CmdSql = new SqlCommand("delete from [Person] where CID=@CID", conn2);
            conn2.Open();
            CmdSql.Parameters.AddWithValue("@CID", Session["CID"]);

            CmdSql.ExecuteNonQuery();
            conn2.Close();



            SqlCommand CmdSql2 = new SqlCommand("delete from [EducationChild] where CID=@CID", conn2);
            conn2.Open();
            CmdSql2.Parameters.AddWithValue("@CID", Session["CID"]);

            CmdSql2.ExecuteNonQuery();
            conn2.Close();


            SqlCommand CmdSql3 = new SqlCommand("delete from [ExistingWelfare] where CID=@CID", conn2);
            conn2.Open();
            CmdSql3.Parameters.AddWithValue("@CID", Session["CID"]);

            CmdSql3.ExecuteNonQuery();
            conn2.Close();


            Response.Redirect("findchild.aspx");


        }


        //Titles


        protected void CMPlanNo()
        {


            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection scon = new SqlConnection(constr);

            //string scon = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlCommand CmdSql47 = new SqlCommand("SELECT TOP 1 [CID],[CMPlanNo] FROM [CMPlan] where CID=@CID order by PlanTime DESC", scon);
            scon.Open();



            CmdSql47.Parameters.AddWithValue("@CID", Session["CID"]);

            SqlDataReader reader = CmdSql47.ExecuteReader();
            // DataTable dt = new DataTable();


            if (reader.Read())
            {
                Session["CMPlanNo"] = reader["CMPlanNo"].ToString();


            }
            else
            {

            }
            scon.Close();
            reader.Close();


        }




        protected void dbotextbox()
        {
            if (birthday.Text.Length > 3)
            {
                //checknumber2();

                string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
                SqlConnection conn2 = new SqlConnection(constr);

                SqlCommand CmdSql = new SqlCommand("UPDATE [Person] SET DOB=@DOB WHERE CID=@CID", conn2);
                conn2.Open();

                CmdSql.Parameters.AddWithValue("@DOB", birthday.Text);
                CmdSql.Parameters.AddWithValue("@CID", Session["CID"]);
                CmdSql.ExecuteNonQuery();
                conn2.Close();
                //MessageBox("ลงทะเบียนเรียบร้อยครับ");




            }
            else
            {
                string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
                SqlConnection conn2 = new SqlConnection(constr);

                SqlCommand CmdSql = new SqlCommand("UPDATE [Person] SET DOB=NULL WHERE CID=@CID", conn2);
                conn2.Open();

                CmdSql.Parameters.AddWithValue("@CID", Session["CID"]);
                CmdSql.ExecuteNonQuery();
                conn2.Close();
                //MessageBox("ลงทะเบียนเรียบร้อยครับ");
            }

        }

        protected void TitlesD_SelectedIndexChanged(object sender, EventArgs e)
        {

            if (TitlesD.SelectedValue == "001")
            {

                GenderR.SelectedValue = "M";

            }
            else if (TitlesD.SelectedValue == "002")
            {
                GenderR.SelectedValue = "F";
            }
            else if (TitlesD.SelectedValue == "003")
            {
                GenderR.SelectedValue = "M";

            }
            else if (TitlesD.SelectedValue == "004")
            {
                GenderR.SelectedValue = "F";
            }
            else if (TitlesD.SelectedValue == "005")
            {
                GenderR.SelectedValue = "F";
            }

        }











    }


        }





    







